//引入request下的axios
import axios from './requests'

export const get = (url: string, params = {}) => {
    return new Promise((resolve, reject) => {
        axios
            .get(url, { params })
            .then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            })
    })
}

export const post = (url: string, params = {}) => {
    return new Promise((resolve, reject) => {
        axios
            .post(url, params)
            .then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            })
    })
}

export const put = (url: string, params = {}) => {
    return new Promise((resolve, reject) => {
        axios
            .put(url, params)
            .then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            })
    })
}

export const patch = (url: string, params = {}) => {
    return new Promise((resolve, reject) => {
        axios
            .patch(url, params)
            .then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            })
    })
}

export const deletes = (url: string, params = {}) => {
    return new Promise((resolve, reject) => {
        axios
            .delete(url, { params })
            .then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            })
    })
}

export const deleteAll = <T>(url: string, params: T) => {
    return new Promise((resolve, reject) => {
        axios({
            method: "delete",
            url: url,
            data: params,
            headers: {
                "Content-Type": "application/json"
            },
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}